/*
 * BlogBackupForm.java
 *
 * Created on 2007年7月22日
 */

package tenyi.util.html;

import javax.swing.JFileChooser;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.htmlparser.util.ParserException;

/**
 *
 * @author  Tenyi
 */
public class BlogBackupForm extends javax.swing.JFrame {
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/** Creates new form BlogBackupForm */
    public BlogBackupForm() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jcbBSP = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jbGo = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jtfNoPerPage = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jtfDirectory = new javax.swing.JTextField();
        jbChoostDirectory = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jcbSaveType = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jtfBlogURL = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Blog 備份");

        jcbBSP.setFont(new java.awt.Font("新細明體", 0, 16));
        jcbBSP.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Xuite", "Wretch", "Blogger" }));

        jLabel1.setFont(new java.awt.Font("新細明體", 0, 16));
        jLabel1.setText("Blog種類");

        jbGo.setFont(new java.awt.Font("新細明體", 0, 16));
        jbGo.setText("備份");
        jbGo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbGoActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("新細明體", 0, 20));
        jLabel3.setText("Blog 備份");

        jLabel4.setFont(new java.awt.Font("新細明體", 0, 16));
        jLabel4.setText("每頁篇數");

        jtfNoPerPage.setFont(new java.awt.Font("新細明體", 0, 16));
        jtfNoPerPage.setText("20");
        jtfNoPerPage.setToolTipText("幾篇分成一頁");

        jLabel5.setFont(new java.awt.Font("新細明體", 0, 16));
        jLabel5.setText("儲存目錄");

        jtfDirectory.setFont(new java.awt.Font("新細明體", 0, 16)); // NOI18N
        jtfDirectory.setText(javax.swing.filechooser.FileSystemView.getFileSystemView().getHomeDirectory().getPath());

        jbChoostDirectory.setText("...");
        jbChoostDirectory.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbChoostDirectoryActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("新細明體", 0, 16));
        jLabel6.setText("儲存格式");

        jcbSaveType.setFont(new java.awt.Font("新細明體", 0, 16));
        jcbSaveType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "RSS", "MT", "HTML" }));

        jLabel7.setFont(new java.awt.Font("新細明體", 0, 16));
        jLabel7.setText("Blog 網址");

        jtfBlogURL.setFont(new java.awt.Font("新細明體", 0, 16));
        jtfBlogURL.setText("http://blog.xuite.net/efchang/network");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(136, 136, 136)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(79, 79, 79)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20)
                .addComponent(jcbBSP, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(151, 151, 151))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(79, 79, 79)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5))
                        .addGap(36, 36, 36)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtfNoPerPage, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jtfBlogURL, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE))
                                    .addComponent(jtfDirectory, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbChoostDirectory, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jcbSaveType, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jbGo))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel3)
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jcbBSP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jtfBlogURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jtfNoPerPage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jbChoostDirectory)
                    .addComponent(jtfDirectory, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jcbSaveType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(39, 39, 39)
                .addComponent(jbGo)
                .addGap(66, 66, 66))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbChoostDirectoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbChoostDirectoryActionPerformed
//    	javax.swing.filechooser.FileSystemView fv =javax.swing.filechooser.FileSystemView.getFileSystemView();
        
        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        int returnVal = chooser.showOpenDialog(this);
        if(returnVal == JFileChooser.APPROVE_OPTION) {
           jtfDirectory.setText(chooser.getSelectedFile().getAbsolutePath());
        }
    }//GEN-LAST:event_jbChoostDirectoryActionPerformed

    private void jbGoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbGoActionPerformed

        try {
        String blogtype = (String) jcbBSP.getSelectedItem();
        String url = jtfBlogURL.getText();
        int numberperpage = Integer.parseInt(jtfNoPerPage.getText());
        String directory = jtfDirectory.getText();
        String savetype = (String) jcbSaveType.getSelectedItem();
        jbGo.setText("備份中，請稍待...");
        jbGo.setEnabled(false);
    	BlogExtractor be = new BlogExtractor();
        be.go(blogtype, url, numberperpage, directory, savetype);
		} catch (ParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
         jbGo.setEnabled(true);
         jbGo.setText("備份");

    }//GEN-LAST:event_jbGoActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
            	String lookAndFeel = UIManager.getSystemLookAndFeelClassName();
            	try {
					UIManager.setLookAndFeel(lookAndFeel);
				} catch (ClassNotFoundException e) {
					e.printStackTrace();
				} catch (InstantiationException e) {
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				} catch (UnsupportedLookAndFeelException e) {
					e.printStackTrace();
				}
             	new BlogBackupForm().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JButton jbChoostDirectory;
    private javax.swing.JButton jbGo;
    private javax.swing.JComboBox jcbBSP;
    private javax.swing.JComboBox jcbSaveType;
    private javax.swing.JTextField jtfBlogURL;
    private javax.swing.JTextField jtfDirectory;
    private javax.swing.JTextField jtfNoPerPage;
    // End of variables declaration//GEN-END:variables
    
}
